<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title>就业学生</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui/css/layui.css">
    <link rel="stylesheet" href="/css/scroll-bar.css">
    <link rel="stylesheet" href="/css/sub-page.css">
    <link rel="stylesheet" href="/lib/nprogress/nprogress.css">
</head>
<body>
<div class="ok-body">
    <!--面包屑导航区域-->
    <div class="ok-body-breadcrumb">
            <span class="layui-breadcrumb">
                <a><cite>首页</cite></a>
                <a><cite>招生就业</cite></a>
                <a><cite>学生列表</cite></a>
            </span>
        <a class="layui-btn layui-btn-sm" href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon layui-icon-refresh"></i>
        </a>
    </div>
    <okToolbar>
        <button class="layui-btn" id="addUser">
            <i class="layui-icon">&#xe61f;</i>添加就业
        </button>
        <span>共有数据：<i id="countNum"></i> 条</span>
    </okToolbar>
    <!--数据表格-->
    <table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>
</div>
<!--模板-->
<script type="text/html" id="photoTpl">
    <img src="{{d.photo}}"/>
</script>
<script type="text/html" id="operationTpl">
    <a href="javascript:;" title="编辑" lay-event="edit"><i class="layui-icon">&#xe642;</i></a>
    <a href="javascript:;" title="删除" lay-event="del"><i class="layui-icon">&#xe640;</i></a>
</script>
<!--js逻辑-->
<script src="/lib/layui/layui.js"></script>

<script src="/lib/nprogress/nprogress.js"></script>
<script>
    // 进度条加载提示
    NProgress.start();
    window.onload = function () {
        NProgress.done();
    }
    // layui相关
    layui.use(['element', 'table', 'form', 'jquery', 'laydate', 'util'], function () {
        let element = layui.element;
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;

        //渲染数据表格
        table.render({
            elem: '#tableId',
            url: '/manage/students/',
            limit: 10,
            page: true,
            even: true,
            cols: [[
                {type: 'checkbox'},
                {field: 'sid', title: 'ID', width: 80},
                {field: 'sname', title: '学生姓名', width: 350},
                {field: 'photo', title: '照片', templet: photoTpl},
                {field: 'sort', title: '排序', width: 90, edit: 'text'},
                {title: '操作', fixed: 'right', minWidth: 80, templet: operationTpl, align: 'center'}
            ]],
            done: function (res, curr, count) {
                $("#countNum").text(count);
            }
        });

        //表格工具列
        table.on('tool(tableFilter)', function (obj) {
            // var data = obj.data;
            let layEvent = obj.event;
            if (layEvent === 'edit') {
                var editLayer = layer.open({
                    title: '编辑就业信息',
                    type: 2,
                    maxmin: true,
                    shade: 0.5,
                    area: ['100%', '100%'],
                    content: '/manage/recruit/student-edit.html?sid=' + obj.data.sid,
                    zIndex: layer.zIndex,
                    ready: function () {
                        //最大化页面层
                        layer.full();
                    },
                    end: function () {
                        $(".layui-laypage-btn")[0].click();
                    }
                });
            } else if (layEvent === 'del') {
                layer.confirm("确定要删除吗？", {skin: 'layui-layer-lan', icon: 2, title: '提示', anim: 6}, function () {
                    $.ajax({
                        url: '/manage/students/' + obj.data.sid,
                        type: 'DELETE',
                        success: function (resp) {
                            layer.msg("操作成功！", {icon: 1, time: 1000});
                            $(".layui-laypage-btn")[0].click();
                        },
                        error: function () {
                            layer.msg("操作失败！", {icon: 1, time: 1000});
                        }
                    })
                });
            }
        });
        //添加文章
        $("#addUser").click(function () {
            var addLayer = layer.open({
                title: '添加就业信息',
                type: 2,
                maxmin: true,
                shade: 0.5,
                anim: 4,
                area: ['90%', '95%'],
                content: '/manage/recruit/student-add.html',
                zIndex: layer.zIndex,
                ready: function () {
                    layer.full();
                },
                end: function () {
                    $(".layui-laypage-btn")[0].click();
                }
            });
        });
        //修改排序
        table.on('edit(tableFilter)', function (obj) {
            let data = {sid: obj.data.sid, sort: obj.value};
            $.ajax({
                url: '/manage/students/',
                data: JSON.stringify(data),
                contentType: 'application/json',
                type: 'PUT',
                // dataType: 'json',
                success: function () {
                    layer.msg("操作成功！", {icon: 6, time: 1000, anim: 4});
                }
                , error: function () {
                    layer.msg("修改失败!", {icon: 5, time: 1000, anim: 4})
                }
            });

        });

    });
</script>

</body>
</html>
